package com.tencent.qcloud.tuikit.tuichat.bean.message;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.CustomRedPackageMessage;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.CustomRedPackageMessageReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;

import java.util.ArrayList;
import java.util.List;

public class CustomRedPackageMessageBean extends TUIMessageBean {

    private CustomRedPackageMessage orderMessage;

    @Override
    public String onGetDisplayString() {
        return getExtra();
    }

    @Override
    public void onProcessMessage(V2TIMMessage v2TIMMessage) {
        String data = new String(v2TIMMessage.getCustomElem().getData());
        TUIChatLog.d("CustomOrderMessageBean", "data = " + data);
        if (!TextUtils.isEmpty(data)) {
            try {
                orderMessage = new Gson().fromJson(data, CustomRedPackageMessage.class);
            } catch (Exception e) {
                TUIChatLog.e("CustomOrderMessageBean", "exception e = " + e);
            }
        }
        if (orderMessage != null) {
            setExtra(TUIChatService.getAppContext().getString(R.string.red_pkg));
        } else {
            String text = TUIChatService.getAppContext().getString(R.string.no_support_msg);
            setExtra(text);
        }
    }

    public String getPkgID() {
        if (orderMessage != null) {
            return orderMessage.pkgID;
        }
        return "";
    }

    public boolean getIsGroup() {
        return isGroup();
    }

    public double getMoney() {
        if (orderMessage != null) {
            return orderMessage.money;
        }
        return 0;
    }
    public int getNum() {
        if (orderMessage != null) {
            return orderMessage.num;
        }
        return 0;
    }

    public String getText() {
        if (orderMessage != null) {
            return orderMessage.text;
        }
        return "";
    }

    public String getSendUName() {
        if (orderMessage != null) {
            return orderMessage.sendUName;
        }
        return "";
    }

    @Override
    public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
        return CustomRedPackageMessageReplyQuoteBean.class;
    }
}
